#include <string>
#include <thread>
#include <chrono>

#include "proto_cpp/addressbook.pb.h"
#include "google/protobuf/util/json_util.h"


int main(int argc, char const *argv[])
{
    AddressBook address_book;
    auto person = address_book.add_people();

    person->set_name("赵树成");
    person->set_id(567);
    person->set_email("bmwshucheng@126.com");

    auto phone = person->add_phones();
    phone->set_number("155 0212 0929");
    phone->set_type(Person::PhoneType::Person_PhoneType_MOBILE);

    person->set_last_updated(45678);

    std::string s;
    // MessageToJsonString(address_book, &s);
    auto res = address_book.SerializeToString(&s);
    std::cout << res << std::endl;
    std::cout << s << std::endl;

    std::string json_s;
    auto json_option = google::protobuf::util::JsonOptions();
    json_option.always_print_enums_as_ints = true;
    json_option.preserve_proto_field_names = true;
    google::protobuf::util::MessageToJsonString(address_book, &json_s, json_option);
    std::cout << json_s << std::endl;

    std::this_thread::sleep_for(std::chrono::milliseconds(1)); // Sleep 250 ms
    return 0;
}
